﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.storage {
    import flash.utils.*;
    import Classes.*;
    import __AS3__.vec.*;

    public class BaseStorageUnit {

        private var m_storage:Dictionary;
        private var m_capacity:int;
        private var m_maxCapacity:int;

        public function BaseStorageUnit(){
            this.m_storage = new Dictionary();
            this.m_capacity = 0;
            this.m_maxCapacity = 0;
        }
        public function loadObject(_arg1:Object):void{
            var _local3:String;
            var _local4:Array;
            var _local5:Object;
            var _local6:ItemInstance;
            var _local2:Object = _arg1["m_storage"];
            for (_local3 in _local2) {
                _local4 = (_local2[_local3] as Array);
                this.m_storage[_local3] = new Vector.<ItemInstance>();
                for each (_local5 in _local4) {
                    _local6 = (Global.world.loadObjectInstance(_local5) as ItemInstance);
                    _local6.loadObject(_local5);
                    this.m_storage[_local3].push(_local6);
                };
            };
            this.m_capacity = int(_arg1["m_capacity"]);
            this.m_maxCapacity = int(_arg1["m_maxCapacity"]);
        }
        public function get capacity():int{
            return (this.m_capacity);
        }
        public function set capacity(_arg1:int):void{
            if (_arg1 > this.m_maxCapacity){
                _arg1 = this.m_maxCapacity;
            };
            this.m_capacity = _arg1;
        }
        public function get maxCapacity():int{
            return (this.m_maxCapacity);
        }
        public function set maxCapacity(_arg1:int):void{
            this.m_maxCapacity = _arg1;
        }
        public function get size():int{
            var _local2:String;
            var _local3:Vector.<ItemInstance>;
            var _local1:int;
            for (_local2 in this.m_storage) {
                _local3 = (this.m_storage[_local2] as Vector.<ItemInstance>);
                _local1 = (_local1 + _local3.length);
            };
            return (_local1);
        }
        public function add(_arg1:ItemInstance):Boolean{
            var _local3:Item;
            var _local4:String;
            var _local5:Vector.<ItemInstance>;
            var _local2:Boolean;
            if (this.size < this.capacity){
                _local3 = _arg1.getItem();
                _local4 = _local3.name;
                if (this.m_storage[_local4] == null){
                    this.m_storage[_local4] = new Vector.<ItemInstance>();
                };
                _local5 = (this.m_storage[_local4] as Vector.<ItemInstance>);
                if (_local5.indexOf(_arg1) < 0){
                    _local5.push(_arg1);
                    _local2 = true;
                };
            };
            return (_local2);
        }
        public function remove(_arg1:ItemInstance):Boolean{
            var _local6:int;
            var _local2:Boolean;
            var _local3:Item = _arg1.getItem();
            var _local4:String = _local3.name;
            var _local5:Vector.<ItemInstance> = this.m_storage[_local4];
            if (_local5 != null){
                _local6 = _local5.indexOf(_arg1);
                if (_local6 >= 0){
                    _local5.splice(_local6, 1);
                    _local2 = true;
                };
                if (_local5.length == 0){
                    delete this.m_storage[_local4];
                };
            };
            return (_local2);
        }
        public function getAllItems():Vector.<ItemInstance>{
            var _local2:Vector.<ItemInstance>;
            var _local3:ItemInstance;
            var _local1:Vector.<ItemInstance> = new Vector.<ItemInstance>();
            for each (_local2 in this.m_storage) {
                for each (_local3 in _local2) {
                    _local1.push(_local3);
                };
            };
            return (_local1);
        }
        public function getItemNames():Vector.<String>{
            var _local2:String;
            var _local1:Vector.<String> = new Vector.<String>();
            for (_local2 in this.m_storage) {
                _local1.push(_local2);
            };
            return (_local1);
        }
        public function getItemsByName(_arg1:String):Vector.<ItemInstance>{
            return ((this.m_storage) ? this.m_storage[_arg1] : null);
        }
        public function getItemsByType(_arg1:String):Vector.<ItemInstance>{
            var _local3:String;
            var _local4:Vector.<ItemInstance>;
            var _local2:Vector.<ItemInstance> = new Vector.<ItemInstance>();
            for (_local3 in this.m_storage) {
                _local4 = (this.m_storage[_local3] as Vector.<ItemInstance>);
                if (((((_local4) && ((_local4.length > 0)))) && ((_arg1 == _local4[0].getItem().type)))){
                    _local2 = _local2.concat(_local4);
                };
            };
            return (_local2);
        }
        public function getItemCountByName(_arg1:String):int{
            var _local2:Vector.<ItemInstance> = this.getItemsByName(_arg1);
            return ((_local2) ? _local2.length : 0);
        }

    }
}//package Modules.storage 
